<!-- 考核供应商 -->
<template>
  <a-card title="考核供应商" :bordered="false">
    <a-form layout="inline" @keyup.enter.native="handleSearch">
      <a-row :gutter="24">
        <a-col :md="6" :sm="24">
          <CompositeSearch
            :fieldList="fieldList"
            @getParams="getSearchValue"
            @adSearch="onAdSearch"
            @adClear="onAdClear"
            @tagClick="onTagClick">
            <template v-slot:ad-search-content>
              <a-form-model
                ref="adSearchFormRef"
                :model="adSearchFormData"
                layout="vertical">
                <a-row :gutter="24">
                  <a-col :span="24">
                    <a-form-model-item label="创建时间">
                      <a-range-picker
                        v-model="createTime"
                        format="YYYY-MM-DD"
                        style="width:100%;"
                        @change="(timeRange, timeStringRange) => setTimeRange('createTimeStart', 'createTimeEnd', timeRange, timeStringRange)"/>
                    </a-form-model-item>
                  </a-col>
                </a-row>
              </a-form-model>
            </template>
          </CompositeSearch>
        </a-col>
        <a-col :md="18" :sm="24">
          <div class="space-btn" style="line-height: 32px;">
            <a-button v-if="!isLook" type="primary" @click="onSelectSupplier">选择供应商</a-button>
            <a-button v-if="!isLook" type="danger" @click="onBatchDelete">批量删除</a-button>
          </div>
        </a-col>
      </a-row>
    </a-form>
    <a-table
      ref="table"
      rowKey="id"
      size="middle"
      bordered
      :loading="loading"
      :columns="columns"
      :dataSource="dataSource"
      :row-selection="{ fixed: true, selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
      :scroll="{ x: 1, y: 400 }"
      :pagination="pagination">
      <span slot="date" slot-scope="text">{{ (text || '/') | DateFormat }}</span>
      <template slot="examineLevel" slot-scope="text">
        <span
          :class="{'cus-text': ['C', 'D'].includes(text)}"
          :warn="text === 'C'"
          :danger="text === 'D'">
          {{ text || '/' }}
        </span>
      </template>
      <template slot="totalExamineScore" slot-scope="text"><span>{{ text || '/' }}</span></template>
      <template slot="autoExamineScore" slot-scope="text, record">
        <span>{{ text || '/' }}</span>
        <a-popover title="自动化考核得分明细" trigger="click">
          <template slot="content">
            <ExamineScoreTable type="auto" :totalScore="text" :examineList="record.autoExamineScoreList || []" />
          </template>
          <a-icon v-if="text" type="info-circle" class="circle-hover ml-10" />
        </a-popover>
      </template>
      <template slot="qualitativeExamineScore" slot-scope="text, record">
        <span>{{ text || '/' }}</span>
        <a-popover title="定性考核得分明细" trigger="click">
          <template slot="content">
            <ExamineScoreTable type="qualitative" :totalScore="text" :examineList="record.qualitativeExamineScoreList || []" />
          </template>
          <a-icon v-if="text" type="info-circle" class="circle-hover ml-10" />
        </a-popover>
      </template>
      <template slot="action" slot-scope="text, record, index">
        <span class="cus-text" pointer @click="onCheck(record)">查看</span>
        <span v-if="!isLook" class="cus-text" pointer danger @click="onDelete(index)">删除</span>
      </template>
    </a-table>
    <!-- 选择供应商 -->
    <SupplierSelect ref="SupplierSelect" @successCallback="supplierSelectCallback" />
  </a-card>
</template>

<script>
import ListPageMixin from '@/mixins/ListPageMixin.js';
import SupplierSelect from '@views/supplier-manage/performace-examine/components/SupplierSelect.vue';
import ExamineScoreTable from '@views/supplier-manage/components/ExamineScoreTable.vue';

export default {
  name: 'BaseInfoAndCondition',
  mixins: [ ListPageMixin ],
  props: {
    isLook: {
      type: Boolean,
      default: false
    }
  },
  components: {
    SupplierSelect,
    ExamineScoreTable
  },
  data() {
    return {
      fieldList: [
        { name: '考核品类', field: 'field1' },
        { name: '绩效编号', field: 'field2' },
        { name: '绩效考核名称', field: 'field3' },
        { name: '考核总数', field: 'field4' }
      ],
      adSearchFormData: {
        createTimeStart: '',
        createTimeEnd: '',
      },
      createTime: [],
      dataSource: [],
      originalDataSource: [
        {
          supplierName: '河南盛世机械工具集团有限公司',
          supplierCode: 'GYS20241208001',
          examineCategory: '传感器供应商',
          examineLevel: 'A',
          totalExamineScore: '98',
          autoExamineScore: '28',
          autoExamineScoreList: [
            { title: '考核项', name: '交货及时率', weight: '80', score: '8' },
            { title: '百分比', name: '入库合格率', weight: '100', score: '10' },
            { title: '得分', name: '使用不良率', weight: '100', score: '10' }
          ],
          qualitativeExamineScore: '70',
          qualitativeExamineScoreList: [
            {
              type: '1',
              name: '价格',
              score: '21',
              children: [
                { name: '价格下降率', score: 10, getScore: 7 },
                { name: '价格弹性', score: 10, getScore: 7 },
                { name: '价格透明度', score: 10, getScore: 7 },
              ]
            },
            { name: '付款条件', score: '14' },
            { name: '履约交互', score: '14' },
            { name: '服务态度', score: '10.5' },
            { name: '品质', score: '10.5' }
          ],
          autoExamineTime: '2024-06-08 11:08:30',
          qualitativeExamineTime: '2024-06-08 11:08:30',
        },
        {
          supplierName: '广州三五零配件有限公司',
          supplierCode: 'GYS20241208001',
          examineCategory: '传感器供应商',
          examineLevel: 'A',
          totalExamineScore: '90',
          autoExamineScore: '28',
          autoExamineScoreList: [
            { title: '考核项', name: '交货及时率', weight: '80', score: '8' },
            { title: '百分比', name: '入库合格率', weight: '100', score: '10' },
            { title: '得分', name: '使用不良率', weight: '100', score: '10' }
          ],
          qualitativeExamineScore: '70',
          qualitativeExamineScoreList: [
            {
              type: '1',
              name: '价格',
              score: '21',
              children: [
                { name: '价格下降率', score: 10, getScore: 7 },
                { name: '价格弹性', score: 10, getScore: 7 },
                { name: '价格透明度', score: 10, getScore: 7 },
              ]
            },
            { name: '付款条件', score: '14' },
            { name: '履约交互', score: '14' },
            { name: '服务态度', score: '10.5' },
            { name: '品质', score: '10.5' }
          ],
          autoExamineTime: '2024-06-08 11:08:30',
          qualitativeExamineTime: '2024-06-08 11:08:30',
        },
        {
          supplierName: '广汽集团广天有限公司',
          supplierCode: 'GYS20241208001',
          examineCategory: '传感器供应商',
          examineLevel: 'A',
          totalExamineScore: '98',
          autoExamineScore: '28',
          autoExamineScoreList: [
            { title: '考核项', name: '交货及时率', weight: '80', score: '8' },
            { title: '百分比', name: '入库合格率', weight: '100', score: '10' },
            { title: '得分', name: '使用不良率', weight: '100', score: '10' }
          ],
          qualitativeExamineScore: '70',
          qualitativeExamineScoreList: [
            { name: '价格', score: '21' },
            { name: '付款条件', score: '14' },
            { name: '履约交互', score: '14' },
            { name: '服务态度', score: '10.5' },
            { name: '品质', score: '10.5' }
          ],
          autoExamineTime: '2024-06-08 11:08:30',
          qualitativeExamineTime: '2024-06-08 11:08:30',
        },
        {
          supplierName: '	河南盛世机械工具集团有限公司',
          supplierCode: 'GYS20241208001',
          examineCategory: '传感器供应商',
          examineLevel: 'A',
          totalExamineScore: '98',
          autoExamineScore: '28',
          autoExamineScoreList: [
            { title: '考核项', name: '交货及时率', weight: '80', score: '8' },
            { title: '百分比', name: '入库合格率', weight: '100', score: '10' },
            { title: '得分', name: '使用不良率', weight: '100', score: '10' }
          ],
          qualitativeExamineScore: '70',
          qualitativeExamineScoreList: [
            { name: '价格', score: '21' },
            { name: '付款条件', score: '14' },
            { name: '履约交互', score: '14' },
            { name: '服务态度', score: '10.5' },
            { name: '品质', score: '10.5' }
          ],
          autoExamineTime: '2024-06-08 11:08:30',
          qualitativeExamineTime: '2024-06-08 11:08:30',
        },
        {
          supplierName: '深圳三五零配件有限公司',
          supplierCode: 'GYS20241208001',
          examineCategory: '传感器供应商',
          examineLevel: 'A',
          totalExamineScore: '98',
          autoExamineScore: '28',
          autoExamineScoreList: [
            { title: '考核项', name: '交货及时率', weight: '80', score: '8' },
            { title: '百分比', name: '入库合格率', weight: '100', score: '10' },
            { title: '得分', name: '使用不良率', weight: '100', score: '10' }
          ],
          qualitativeExamineScore: '70',
          qualitativeExamineScoreList: [
            { name: '价格', score: '21' },
            { name: '付款条件', score: '14' },
            { name: '履约交互', score: '14' },
            { name: '服务态度', score: '10.5' },
            { name: '品质', score: '10.5' }
          ],
          autoExamineTime: '2024-06-08 11:08:30',
          qualitativeExamineTime: '2024-06-08 11:08:30',
        },
        {
          supplierName: '深圳集团广天有限公司',
          supplierCode: 'GYS20241208001',
          examineCategory: '驱动电机',
          examineLevel: 'A',
          totalExamineScore: '98',
          autoExamineScore: '28',
          autoExamineScoreList: [
            { title: '考核项', name: '交货及时率', weight: '80', score: '8' },
            { title: '百分比', name: '入库合格率', weight: '100', score: '10' },
            { title: '得分', name: '使用不良率', weight: '100', score: '10' }
          ],
          qualitativeExamineScore: '70',
          qualitativeExamineScoreList: [
            { name: '价格', score: '21' },
            { name: '付款条件', score: '14' },
            { name: '履约交互', score: '14' },
            { name: '服务态度', score: '10.5' },
            { name: '品质', score: '10.5' }
          ],
          autoExamineTime: '2024-06-08 11:08:30',
          qualitativeExamineTime: '2024-06-08 11:08:30',
        },
        {
          supplierName: '盛世机械工具集团有限公司',
          supplierCode: 'GYS20241208001',
          examineCategory: '驱动电机',
          examineLevel: 'A',
          totalExamineScore: '98',
          autoExamineScore: '28',
          autoExamineScoreList: [
            { title: '考核项', name: '交货及时率', weight: '80', score: '8' },
            { title: '百分比', name: '入库合格率', weight: '100', score: '10' },
            { title: '得分', name: '使用不良率', weight: '100', score: '10' }
          ],
          qualitativeExamineScore: '70',
          qualitativeExamineScoreList: [
            { name: '价格', score: '21' },
            { name: '付款条件', score: '14' },
            { name: '履约交互', score: '14' },
            { name: '服务态度', score: '10.5' },
            { name: '品质', score: '10.5' }
          ],
          autoExamineTime: '2024-06-08 11:08:30',
          qualitativeExamineTime: '2024-06-08 11:08:30',
        },
        {
          supplierName: '湛江三五零配件有限公司',
          supplierCode: 'GYS20241208001',
          examineCategory: '驱动电机',
          examineLevel: 'A',
          totalExamineScore: '98',
          autoExamineScore: '28',
          autoExamineScoreList: [
            { title: '考核项', name: '交货及时率', weight: '80', score: '8' },
            { title: '百分比', name: '入库合格率', weight: '100', score: '10' },
            { title: '得分', name: '使用不良率', weight: '100', score: '10' }
          ],
          qualitativeExamineScore: '70',
          qualitativeExamineScoreList: [
            { name: '价格', score: '21' },
            { name: '付款条件', score: '14' },
            { name: '履约交互', score: '14' },
            { name: '服务态度', score: '10.5' },
            { name: '品质', score: '10.5' }
          ],
          autoExamineTime: '2024-06-08 11:08:30',
          qualitativeExamineTime: '2024-06-08 11:08:30',
        },
        {
          supplierName: '广天集团广天有限公司',
          supplierCode: 'GYS20241208001',
          examineCategory: '驱动电机',
          examineLevel: 'A',
          totalExamineScore: '98',
          autoExamineScore: '28',
          autoExamineScoreList: [
            { title: '考核项', name: '交货及时率', weight: '80', score: '8' },
            { title: '百分比', name: '入库合格率', weight: '100', score: '10' },
            { title: '得分', name: '使用不良率', weight: '100', score: '10' }
          ],
          qualitativeExamineScore: '70',
          qualitativeExamineScoreList: [
            { name: '价格', score: '21' },
            { name: '付款条件', score: '14' },
            { name: '履约交互', score: '14' },
            { name: '服务态度', score: '10.5' },
            { name: '品质', score: '10.5' }
          ],
          autoExamineTime: '2024-06-08 11:08:30',
          qualitativeExamineTime: '2024-06-08 11:08:30',
        },
        {
          supplierName: '万盛世机械工具集团',
          supplierCode: 'GYS20241208001',
          examineCategory: '驱动电机',
          examineLevel: 'A',
          totalExamineScore: '98',
          autoExamineScore: '28',
          autoExamineScoreList: [
            { title: '考核项', name: '交货及时率', weight: '80', score: '8' },
            { title: '百分比', name: '入库合格率', weight: '100', score: '10' },
            { title: '得分', name: '使用不良率', weight: '100', score: '10' }
          ],
          qualitativeExamineScore: '70',
          qualitativeExamineScoreList: [
            { name: '价格', score: '21' },
            { name: '付款条件', score: '14' },
            { name: '履约交互', score: '14' },
            { name: '服务态度', score: '10.5' },
            { name: '品质', score: '10.5' }
          ],
          autoExamineTime: '2024-06-08 11:08:30',
          qualitativeExamineTime: '2024-06-08 11:08:30',
        }
      ],
      columns: [
        { title: '序号', width: 50, customRender: (text, record, index) => `${index + 1}`, align: 'center' },
        { title: '供应商', dataIndex: 'supplierName', width: 220, ellipsis: true },
        { title: '供应商编号', dataIndex: 'supplierCode', width: 150, ellipsis: true },
        { title: '所属品类', dataIndex: 'examineCategory', width: 150, ellipsis: true },
        { title: '考核等级', dataIndex: 'examineLevel', width: 120, scopedSlots: { customRender: 'examineLevel' }, ellipsis: true },
        { title: '总得分', dataIndex: 'totalExamineScore', width: 120, scopedSlots: { customRender: 'totalExamineScore' }, ellipsis: true },
        { title: '自动化考核得分', dataIndex: 'autoExamineScore', width: 120, scopedSlots: { customRender: 'autoExamineScore' }, ellipsis: true },
        { title: '定性考核得分', dataIndex: 'qualitativeExamineScore', width: 120, scopedSlots: { customRender: 'qualitativeExamineScore' }, ellipsis: true },
        { title: '自动化考核时间', dataIndex: 'autoExamineTime', width: 120, scopedSlots: { customRender: 'date' }, ellipsis: true },
        { title: '定性考核时间', dataIndex: 'qualitativeExamineTime', width: 120, scopedSlots: { customRender: 'date' }, ellipsis: true },
        { title: '操作', dataIndex: 'action', width: 150, align: 'center', fixed: 'right', scopedSlots: { customRender: 'action' } }
      ],
    }
  },
  created() {
    this.handleSearch();
  },
  methods: {
    setParams() {},
    getParams() {},
    // 获取 搜索框参数
    getSearchValue(currentValue, selectFiledList) {
      console.log(currentValue, selectFiledList, 'getSearchValue');
      this.handleSearch();
    },
    // 确定搜索 高级搜索
    onAdSearch() {
      console.log(this.adSearchFormData, '确定搜索 高级搜索');
      this.handleSearch();
    },
    // 重置 高级搜索
    onAdClear() {
      console.log('重置 高级搜索');
    },
    onTagClick(data) {
      console.log(data, 'onTagClick');
      const { name } = data;
      if (['筛选组合01', '筛选组合02', '筛选组合03'].includes(name)) {
        this.adSearchFormData.supplierStatus = '1';
        this.adSearchFormData.approveStatus = '1';
      } else if (['筛选组合04', '筛选组合05', '筛选组合06'].includes(name)) {
        this.adSearchFormData.supplierStatus = '2';
        this.adSearchFormData.approveStatus = '2';
      } else {
        this.adSearchFormData.supplierStatus = '3';
        this.adSearchFormData.approveStatus = '3';
      }
    },
    handleSearch() {
      this.loading = true;
      setTimeout(() => {
        this.loading = false;
        this.onSelectClear();
        this.dataSource = this.originalDataSource
      }, 100)
    },
    onSelectSupplier() {
      this.$refs.SupplierSelect.onDrawerOpen();
    },
    // 批量删除
    onBatchDelete() {
      if (this.selectedRowKeys.length) {
        this.$confirm({
          title: '批量删除',
          content: '确认批量删除？',
          okText: '确认',
          cancelText: '取消',
          onOk: () => {
            this.handleSearch();
            this.$message.success(`操作成功`);
          }
        });
      } else {
        this.$message.error(`请选择数据！`);
      }
    },
    // 删除
    onDelete(index) {
      this.$confirm({
        title: '删除',
        content: '确认删除？',
        okText: '确认',
        cancelText: '取消',
        onOk: () => {
          this.dataSource.splice(index, 1);
          this.handleSearch();
          this.$message.success(`操作成功`);
        }
      });
    },
    supplierSelectCallback() {

    },
  }
}
</script>

<style lang="less" scoped>
</style>